
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f2f2f2;
        }
        .container {
            position: relative;
            top: 180px;
            width: 380px;
            margin: 0 auto;
            padding: 20px;
            background-color: white;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            margin-bottom: 20px;
        }
        input[type="text"], input[type="password"] {
            width: 90%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
        }
        button {
            width: 50%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <div class="container">
        <center>
            <h1>Login</h1>
        <!-- <form action="/login" method="post"> -->
            <input type="text" name="username" placeholder="请输入账号" required id="name">
            <input type="password" name="password" placeholder="请输入密码" required id="password">
            <button type="submit" onclick="login()">Login</button>
            <p><label id="msg"></label></p>
            
        <!-- </form> -->
        </center>
    </div>
    <script>
        function login(){
            let name = document.getElementById('name').value
            let password = document.getElementById('password').value

            let data={
                name:name,
                password:password
            }

            submit(data);
        }

        function submit(data){
            const xhr = new XMLHttpRequest()
            let method ='post'
            let url = '/login'
            xhr.open(method,url,true)
            xhr.send(JSON.stringify(data))
            xhr.onreadystatechange = function(){
                if(xhr.readyState===4 && xhr.status===200){
                    let res = xhr.responseText;
                    let stus = JSON.parse(res)
                    
                    let label =document.getElementById('msg')
                    label.innerText = stus
                }
            }
        }        
        
    </script>
</body>
</html>